
{% extends 'dashboard/base.html' %}

{% block body %}
{#<link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.css" rel="stylesheet">#}

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body">
                        <div class="float-right">
                            <!--<div class="btn-group" role="group" aria-label="Basic example">-->
                            <!--<a href="/webscanners/xml_upload" class="btn btn-primary btn-mini"><i-->
                            <!--class="icon-upload-alt"></i> Upload XML</a>-->
                            <!--</div>-->
                            {% if user.is_superuser == True or user.role.id == 2 %}
                            <div class="btn-group"><a href="{% url 'pentest:add_list_scan' %}"
                                                      class="btn btn-primary btn-mini" data-toggle="tooltip" data-placement="top" title="Add New Pentest"><i
                                    class="fas fa-plus-circle"></i> Add</a>
                            </div>

                            <button type="button" class="btn btn-danger btn-mini" onclick="">Delete Selected</button>
                            {% endif %}
                        </div>
                        <br>
                        <br>
                        <div class="d-md-flex align-items-center">
                            <h1 class="card-title">Pentest List</h1>
                        </div>
                        <br>
                        <div class="row">
                            <div class="table-responsive">
                                <table id="manual_scans_list" class="table table-bordered data-table">
                                    <thead>
                                    <tr>
                                        <th><label class="customcheckbox m-b-20">
                                            <input type="checkbox" id="mainCheckbox">
                                            <span class="checkmark"></span>
                                        </label></th>
                                        <th>URL</th>
                                        <th>Date Time</th>
                                        <th>Total Vulnerability</th>
                                        <th>High</th>
                                        <th>Medium</th>
                                        <th>Low</th>
                                        {% if user.is_superuser == True or user.role.id == 2 %}
                                        <th>Action</th>
                                        {% endif %}
                                    </tr>
                                    </thead>
                                    <tbody>{% for data in pentest %}
                                    <tr data-target="#">
                                        <td>
                                            <form>
                                                <label class="customcheckbox">
                                                    <input type="checkbox" class="listCheckbox"
                                                           value="{{data.scan_id}}"
                                                           name="del_scan_id"
                                                           onClick="reload">
                                                    <span class="checkmark"></span>
                                                </label>
                                            </form>
                                        </td>
                                        <td>
                                            <a href="{% url 'pentest:vuln_list' %}?scan_id={{data.scan_id}}&project_id={{ data.project.uu_id }}">{{data.scan_url}}</a>
                                        </td>
                                        <td>{{data.date_time}}</td>
                                        <td><span class="badge badge-pill badge-dark">{{data.total_vul}}</span></td>
                                        <td><span class="badge badge-pill badge-danger">{{data.high_vul}}</span></td>
                                        <td><span class="badge badge-pill badge-warning">{{data.medium_vul}}</span></td>
                                        <td><span class="badge badge-pill badge-info">{{data.low_vul}}</span></td>
                                       {% if user.is_superuser == True or user.role.id == 2 %}
                                        <td class="confirm-delete">
                                            <form action="{% url 'pentest:del_scan' %}" method="post" class="forms-sample">

                                                {% csrf_token %}
                                                <input type="hidden" name="scan_id" value="{{data.scan_id}}"/>
                                                <input type="hidden" name="scan_url" value="{{data.scan_url}}"/>
                                                <button class="btn btn-warning btn-mini"><i class="fas fa-trash"></i></button>
                                            </form>
                                        </td>
                                    {% endif %}
                                    </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

{#<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>#}
{#<script src="/static/matrix-admin-bt4/assets/libs/toastr/build/toastr.min.js"></script>#}
{#<script src="/static/matrix-admin-bt4/dist/js/custom.min.js"></script>#}
<script type="text/javascript">

    $("#checkAll").change(function () {
        $("input:checkbox").prop('checked', $(this).prop("checked"));
    });
    $(document).ready(function() {
        $('.btn-danger').click(function(){
            if (confirm('Are you sure you want to delete this?')) {
                var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
                $.each($("input[name='del_scan_id']:checked"), function(){
                    scan_id.push($(this).val());
                });

                var json_scanid = scan_id.join(", ");
                $.ajax({
                    type:'POST',
                    <!--contentType: 'application/json; charset=utf-8',-->
                    url:'{% url 'pentest:del_scan' %}',
                    data:{
                       scan_id: json_scanid,
                       csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
                    },
                    sucess:function(){

                    }
                });
                setTimeout(location.reload(), 6000);
            }
        });

    });

$(document).on('click', '.confirm-delete', function(){
    return confirm('Are you sure you want to delete this?');
})

</script>
{% endblock %}